#include "common.h"
namespace common {
int lastRemainingRec(int n, int m) {
    if (n == 1)
        return 0;
    else {
        return (lastRemainingRec(n - 1, m) + m) % n;
    }
}

int lastRemaining(int n, int m) {
    int x = 0;
    for (int i = 2; i <= n; i++) {
        x = (x + m) % i;
    }
    return x;
}
} // namespace common
